# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=oh-my-posh
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=25.23.0
pkgrel=1
pkgdesc="A prompt theme engine for any shell (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/JanDeDobbeleer/oh-my-posh"
msys2_documentation_url="https://ohmyposh.dev"
msys2_references=(
    'aur: oh-my-posh'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-go"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: to have icons in prompt themes")
source=("https://github.com/JanDeDobbeleer/oh-my-posh/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a51432663462ff79318b3ff4bc8d956c8ae0831df9f324a96f58e9532dbe4db8')

build() {
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

    cd "${_realname}-${pkgver}/src"
    go build \
      -ldflags="-linkmode=external \
      -X github.com/jandedobbeleer/oh-my-posh/src/build.Version=${pkgver} \
      -X github.com/jandedobbeleer/oh-my-posh/src/build.Date=$(date --utc --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" --iso-8601=seconds)" \
      -o "${_realname}.exe"
}

package() {
    cd "${_realname}-${pkgver}/src"
    install -Dm755 "${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
    install -Dm644 "../COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 ../themes/* -t "${pkgdir}${MINGW_PREFIX}/share/oh-my-posh/themes"
}
